package com.wires.lu.practice;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * ArrayBlockingQueue:是一个基于数组结构的有界堵塞队列，此队列按FIFO(先进先出)原则对于元素进行排序
 * LinkedBlockingQueue：是一个基于链表结构的堵塞队列,此队列按FIFO(先进先出)排序元素，吞吐量通常要高于ArrayBlockingQueue
 * SynchronousQueue:一个不存储元素的阻塞队列，每个插入操作必须等到另一个线程调用移除操作，否则插入操作一直处于堵塞状态，吞吐量通常要高于
 *
 * 1.队列
 *
 * 2.堵塞队列
 *   2.1堵塞队列有没有好的一面
 *
 *   2.2不得不堵塞，你如何管理
 *
 */


public class BlockingQueueDemo {

    public static void main(String[] args) throws  Exception {
        List list=new ArrayList();
        BlockingQueue<String> blockingDeque=new ArrayBlockingQueue<>(3);
        /*System.out.println(blockingDeque.add("a"));//插入 抛异常
        System.out.println(blockingDeque.add("b"));
        System.out.println(blockingDeque.add("c"));//
        System.out.println(blockingDeque.element());//检查队列是否为空，不为空输出队首元素
        System.out.println( blockingDeque.remove());//移除 抛异常
        System.out.println( blockingDeque.remove());
        System.out.println( blockingDeque.remove());*/
        /*System.out.println(blockingDeque.offer("a"));//插入 布尔值
        System.out.println(blockingDeque.offer("b"));
        System.out.println(blockingDeque.offer("c"));
        System.out.println(blockingDeque.offer("x"));
        System.out.println(blockingDeque.peek());
        System.out.println(blockingDeque.poll()) ;
        System.out.println(blockingDeque.poll()) ;
        System.out.println(blockingDeque.poll()) ;
        System.out.println(blockingDeque.poll()) ;*///移除 阻塞
        /*blockingDeque.put("a");
        blockingDeque.put("a");
        blockingDeque.put("a");//插入 阻塞
        //blockingDeque.put("z");
        blockingDeque.take();
        blockingDeque.take();
        blockingDeque.take();
        blockingDeque.take();//移除 堵塞

        blockingDeque.offer("a",2L, TimeUnit.SECONDS);// 插入 堵塞超市 取消
        blockingDeque.offer("b",2L, TimeUnit.SECONDS);
        blockingDeque.offer("c",2L, TimeUnit.SECONDS);
        blockingDeque.offer("d",2L, TimeUnit.SECONDS);
        blockingDeque.poll(2L,TimeUnit.SECONDS);//移除 阻塞超时取消
        blockingDeque.poll(2L,TimeUnit.SECONDS);
        blockingDeque.poll(2L,TimeUnit.SECONDS);
        blockingDeque.poll(2L,TimeUnit.SECONDS);
        blockingDeque.poll(2L,TimeUnit.SECONDS);*/




    }
}
